/**
 * Copyright SunEEE Limited (c) 2014. All rights reserved.
 * This software is proprietary to and embodies the confidential
 * technology of SunEEE Limited.  Possession, use, or copying
 * of this software and media is authorized only pursuant to a
 * valid written license from SunEEE or an authorized sublicensor.
 */
package com.base.core.util;

import com.base.core.error.Assert;
import org.apache.commons.codec.digest.DigestUtils;


/**
 * ZhiLi:      MD5加密
 * @version   Revision History
 * <pre>
 * Author     Version       Date              Changes
 * ZhiLi      1.0           2014年11月6日     Created
 *
 * </pre>
 * @since B2B1.0.0
 */

public abstract class MD5Utils {

    /**
     * MD5加密
     * @param 
     * @return
     */
    public static String md5(String source) {
        Assert.notEmpty(source, "source");

        //采用java类库 commons-codec
        return DigestUtils.md5Hex(source);
        
//        byte[] digest = MD5Utils.digest(source.getBytes());
//
//        //把密文转换成十六进制的字符串形式
//        int j = digest.length;
//        char str[] = new char[j * 2];
//        int k = 0;
//        for (int i = 0; i < j; i++) {
//            byte b = digest[i];
//            str[k++] = HEXDIGITS[b >>> 4 & 0xf];
//            str[k++] = HEXDIGITS[b & 0xf];
//        }
//        return new String(str);
    }

//    /**
//     * 获取加密字节数组
//     * @param bs
//     * @return
//     */
//    private static synchronized byte[] digest(byte[] bs) {
//        //获得密文  
//        return md.digest(bs);
//    }

    public static void main(String[] args) {
        System.out.println(DigestUtils.md5Hex("123456"));
        //e10adc3949ba59abbe56e057f20f883e
    }

}
